package com.sec.android.app.myfiles.module.search;

import com.sec.android.app.myfiles.info.FileType;
import com.sec.android.app.myfiles.provider.DbTableInfo;

public class SearchDbTableInfo extends DbTableInfo {
    private static SearchDbTableInfo mInstance = null;

    public static DbTableInfo getInstance() {
        if (mInstance == null) {
            mInstance = new SearchDbTableInfo();
        }
        return mInstance;
    }

    private SearchDbTableInfo() {
        String nameQuery = "substr(_data,1+length(rtrim(_data,replace(_data,'/','')))) as searchName";
        String pathQuery = "rtrim(_data, _display_name) as parentPath";
        String isDirQuery = "case when format = " + FileType.FOLDER + " then 1 else 0 end as isDirectory";

        mTableColumn.add(new DB_Column(COLUMN_ID.ID, "_id", "integer PRIMARY KEY"));
        mTableColumn.add(new DB_Column(COLUMN_ID.PATH, "_data", "text"));
        mTableColumn.add(new DB_Column(COLUMN_ID.NAME, "searchName", null, nameQuery));
        mTableColumn.add(new DB_Column(COLUMN_ID.SIZE, "_size", "integer"));
        mTableColumn.add(new DB_Column(COLUMN_ID.FORMAT, "format", "integer"));
        mTableColumn.add(new DB_Column(COLUMN_ID.DATE, "date_modified", "integer"));
        mTableColumn.add(new DB_Column(COLUMN_ID.FILE_TYPE, "media_type", "integer"));
        mTableColumn.add(new DB_Column(COLUMN_ID.MIME_TYPE, "mime_type", "text"));
        mTableColumn.add(new DB_Column(COLUMN_ID.PARENT, "parentPath", null, pathQuery));
        mTableColumn.add(new DB_Column(COLUMN_ID.EXT, "ext", null, EXT_QUERY + " AS ext"));
        mTableColumn.add(new DB_Column(COLUMN_ID.IS_DIRECTORY, "isDirectory", null, isDirQuery));
        mTableColumn.add(new DB_Column(COLUMN_ID.SEF_FILE_TYPE, COLUMN_NAME_SEF_FILE_TYPE, "integer"));
        mTableColumn.add(new DB_Column(COLUMN_ID.IS_360_VIDEO, COLUMN_NAME_GEAR360_VIDEO, "integer"));
    }

    @Override
    public String getTableName() {
        return "myfiles_search";
    }

    @Override
    public boolean isRealDb() {
        return false;
    }

}
